var express = require('express');
var router = express.Router();

let {orderModel,orcateModel} = require('../model/model/qi')

router.post('/order_add',(req,res)=>{
    orderModel.create(req.body)
   .then((data)=>{
        res.send({err:0,msg:'添加成功'})
    })
})
router.get('/order_list',async(req,res)=>{
    let data = await orderModel.find()
    res.send({err:0,msg:'查询成功',data:data})

})
router.post('/order_cate',async(req,res)=>{
    let {i} = req.body
    console.log(i)
    if(i==1){

        let data = await orderModel.find()
        res.send({err:0,msg:'查询成功',data:data})
    }else{
        let data = await orderModel.find({cate:i})
        res.send({err:0,msg:'查询成功',data:data})
    }
 
})

router.post('/orcate_add',(req,res)=>{
     orcateModel.create(req.body)
   .then((data)=>{
        res.send({err:0,msg:'添加成功'})
    })
})

router.get('/orcate_list',async(req,res)=>{
    let data = await orcateModel.find()
    res.send({err:0,msg:'查询成功',data:data})
})

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;
